home *** CD-ROM | disk | FTP | other *** search
- #include <Fonts.h>
- #include <MacWindows.h>
- #include <QuickDraw.h>
-
- #define kSwell 15
- #define kVOffset 6
- #define kHOffset 7
-
- #define Rand(min, max) (((Random() & 0x7FFF) % ((max)-(min))) + (min))
-
- void Swell(Rect * foo);
- void Initalize(void);
- pascal OSStatus GetWindowBounds(WindowRef window, WindowRegionCode regionCode, Rect *globalBounds);
- Boolean DoKey(int k, unsigned char gkm[16]);
-
- SndChannelPtr theChannel;
-
- Boolean DoKey(int k, unsigned char gkm[16])
- {
- return((gkm[k>>3]>>(k&7))&1);
- }
-
-
- static void Initialize(void)
- {
- qd.randSeed = TickCount();
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- InitCursor();
- InitDialogs(nil);
- TEInit();
- MoreMasters();
- SndNewChannel(&theChannel, sampledSynth, initMono, NULL);
- }
-
- pascal OSStatus GetWindowBounds(WindowRef window,
- WindowRegionCode regionCode,Rect *globalBounds)
- {
- OSStatus anErr = noErr;
- // GrafPtr savePort;
- Rect tRect;
-
- // GetPort(&savePort);
- // SetPort(window);
-
- tRect = (*((WindowPeek) window)->contRgn)->rgnBBox;
-
- if (nil != globalBounds)
- *globalBounds = tRect;
- else
- anErr = paramErr;
-
- // SetPort(savePort);
-
- return anErr;
- }
-
- void Swell(Rect * swellee)
- {
- swellee->left -= kSwell;
- if(swellee->left < 0)
- swellee->left = 1;
-
- swellee->right += kSwell;
- swellee->top -= kSwell/2;
- if(swellee->top < 0)
- swellee->top = 1;
-
- swellee->bottom += kSwell*2;
- }
-
- void main(void)
- {
- WindowPeek baseWindow;
- WindowRef tWindowRef1,tWindowRef2,tWindowRef3,tWindowRef4;
- Rect wRect = { 20,20,200,820}, mainRect;
- Handle wHandle, dHandle;
- unsigned char map[16];
-
- Initialize();
-
- tWindowRef1 = NewCWindow(nil,&wRect,"\pMyWindow1",true,kStandardWindowDefinition,(WindowRef) -1,false,0);
- SetRect(&wRect, 120,75,250,732);
- tWindowRef2 = NewCWindow(nil,&wRect,"\pMyWindow2",true,kStandardWindowDefinition,(WindowRef) -1,false,0);
- SetRect(&wRect, 100,50,220,200);
- tWindowRef3 = NewCWindow(nil,&wRect,"\pMyWindow3",true,kStandardWindowDefinition,(WindowRef) -1,false,0);
- SetRect(&wRect,180,100, 590, 560);
- tWindowRef4 = NewCWindow(nil,&wRect,"\pMyWindow4",true,kStandardWindowDefinition,(WindowRef) -1,false,0);
-
- wHandle = GetResource('snd ', 128);
- dHandle = GetResource('snd ', 129);
-
- GetKeys((unsigned long *)map);
- if(DoKey(56, map))
- return;
-
- baseWindow = (WindowPeek) LMGetWindowList();
-
- if(wHandle)
- {
- HLock(wHandle);
- // SndPlay(theChannel, (SndListHandle)wHandle, false);
- // SndPlay(theChannel, (SndListHandle)wHandle, false);
- HUnlock(wHandle);
- }
-
- (void) GetWindowBounds((WindowPtr) baseWindow,kWindowGlobalPortRgn,&mainRect);
- Swell(&mainRect);
-
- while (nil != baseWindow)
- {
- Point tDelta;
- short direction = Rand(0, 3);
- Rect tRect, * subRect;
- baseWindow = baseWindow->nextWindow;
- if(nil==baseWindow) break;
-
-
- (void) GetWindowBounds((WindowPtr) baseWindow,kWindowGlobalPortRgn,&wRect);
-
- while(SectRect(&mainRect, &wRect, nil))
- {
- tDelta.h = tDelta.v = 0;
- switch(direction)
- {
- case 0:
- case 4:
- case 8:
- case 12:
- tDelta.h=kHOffset;
- break;
- case 1:
- case 5:
- case 9:
- tDelta.v=-kVOffset;
- break;
- case 2:
- case 6:
- case 10:
- tDelta.h=-kHOffset;
- break;
- case 3:
- case 7:
- case 11:
- tDelta.v=kVOffset;
- break;
- }
-
- tDelta.h += Rand(-2,2);
- tDelta.v += Rand(-1,1);
-
- GetKeys((unsigned long *)map);
- if(DoKey(56, map))
- return;
-
- OffsetRect(&wRect,tDelta.h,tDelta.v);
- MoveWindow((WindowPtr)baseWindow, wRect.left, wRect.top, false);
-
- // (void) GetWindowBounds((WindowPtr) baseWindow,kWindowGlobalPortRgn,&wRect);
-
- SectRect(&qd.screenBits.bounds, &wRect, &tRect);
- if(!EqualRect(&wRect, &tRect))
- {
- MoveWindow((WindowPtr)baseWindow, wRect.left - tDelta.h, wRect.top - tDelta.v, false);
- direction++;
- (void) GetWindowBounds((WindowPtr) baseWindow,kWindowGlobalPortRgn,&wRect);
- if(dHandle)
- {
- HLock(dHandle);
- // SndPlay(theChannel, (SndListHandle)dHandle, true);
- HUnlock(dHandle);
- }
-
- }
- if(direction > 12)
- break;
- }
- }
- }
-
-